#include <stdlib.h>
#include "global.h"

void bzero (register char *b, register int length)
{
#ifdef VMS
	short zero = 0;
	long max_str = 65535;

	while (length > max_str)
	{
		(void) LIB$MOVC5 (&zero, &zero, &zero, &max_str, b);
		length -= max_str;
		b += max_str;
	}
	(void) LIB$MOVC5 (&zero, &zero, &zero, &length, b);
#else
	while (length-- > 0)
		*b++ = 0;
#endif /* not VMS */
}

void memory_full()
{

}

char *
xcalloc (int number, int size)
{
  register int total = number * size;
  register char *ptr = (char *)malloc (total);
  if (ptr != 0)
    {
      if (total > 100)
	bzero (ptr, total);
      else {
	/* It's not too long, so loop, zeroing by longs.
	   It must be safe because malloc values are always well aligned.  */
	register long *zp = (long *) ptr;
	register long *zl = (long *) (ptr + total - 4);
	register int i = total - 4;
	while (zp < zl)
	  *zp++ = 0;
	if (i < 0)
	  i = 0;
	while (i < total)
	  ptr[i++] = 0;
      }
      return ptr;
    }
  memory_full ();
  /*NOTREACHED*/
}


char *xmalloc (int size)
{
	register char *ptr = (char *)malloc (size);
	if (ptr != 0) return (ptr);
	else
		return NULL;
	//memory_full ();
	/*NOTREACHED*/
}
